import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import 'MineLocalizations.dart';

class MineLocalizationsDelegate
    extends LocalizationsDelegate<MineLocalizations> {
  const MineLocalizationsDelegate();

  static const supportArray = ['en', 'zh'];

  //是否支持某个Local
  @override
  bool isSupported(Locale locale) {
    return supportArray.contains(locale.languageCode);
  }

  // Flutter会调用此类加载相应的Locale资源类
  @override
  Future<MineLocalizations> load(Locale locale) {
    print("MineLocalizationsDelegate >> $locale");
    return SynchronousFuture<MineLocalizations>(
        MineLocalizations(locale.languageCode == "zh"));
  }

  /// 决定当Localizations组件重新build时
  @override
  bool shouldReload(covariant LocalizationsDelegate<MineLocalizations> old) {
    return false;
  }
}
